import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import FootnavPhone from '@/components/base/phone/footnav-phone/footnav-phone'
import BcFooter from '@/components/bc-footer/bc-footer'
import BcFooterSub from '@/components/bc-footer/bc-footer-sub'
import BcHeader from '@/components/header/main-header/main-header'
import Home from '@/pages/home/home'
import BcNews from '@/pages/bc-news/bc-news'
import BcElectronic from '@/pages/bc-electronic/bc-electronic'
import BcMatches from '@/pages/bc-matches/bc-matches'
import BcActivity from '@/pages/bc-activity/bc-activity'
import Login from '@/pages/login/login'
import Signup from '@/pages/login/signup'
import FindPwd from '@/pages/login/find-pwd'
import BcMe from '@/pages/bc-me/bc-me'
import SelectNumber from '@/pages/select-number/select-number'
import BjRacer from '@/pages/select-number/components/bj-racer'
import CqSsc from '@/pages/select-number/components/cq-ssc'
import XgLhc from '@/pages/select-number/components/xg-lhc'
import XyKs from '@/pages/select-number/components/xy-ks'
import JsXw from '@/pages/select-number/components/js-xw'
import BjEb from '@/pages/select-number/components/bj-eb' 
import OrderUnsettle from '@/pages/lottery-order/order-unsettle'
import OrderRecords from '@/pages/lottery-order/order-records'
import OrderSuccess from '@/components/base/phone/order-success/order-success'
import OrderConfirmation from '@/components/order-confirmation/order-confirmation'

import BuyLottery from '@/pages/buy-lottery/buy-lottery'
import MyAccount from '@/pages/my-account/my-account'
import MyWallet from '@/pages/my-account/components/my-wallet'
import MyMsg from '@/pages/my-account/components/my-msg'
import MySettings from '@/pages/my-account/components/my-settings'
import SettingsPhone from '@/pages/my-account/components/settings-phone'
import MyReport from '@/pages/my-report/my-report'
import MemberManagement from '@/pages/member-management/member-management'
import RecommendLink from '@/pages/member-management/components/recommend-link'
import AddLink from '@/pages/member-management/components/add-link'
import LinkDetail from '@/pages/member-management/components/link-detail'
import AddMembers from '@/pages/add-members/add-members'
import AccountUpdate from '@/pages/account-update/account-update'

import PersonalDetail from '@/pages/account-update/components/personal-detail'
import MemberDetail from '@/pages/account-update/components/member-detail'
import LotteryTrends from '@/pages/lottery-trends/lottery-trends'

const router = new Router({
    routes: [
        {
          path: '/',
          redirect: '/home',
        },
        {
          path: '/vnews',
          name: 'vnews',
          components: {
            default: BcNews,
            footerpc: BcFooter,
            headerpc: BcHeader
          },
        },
        {
          path: '/electronics',
          name: 'electronic',
          components: {
            default: BcElectronic,
            footerpc: BcFooter,
            headerpc: BcHeader
          }
        },
        {
          path: '/matches',
          name: 'matches',
          components: {
            default: BcMatches,
            footerpc: BcFooter,
            headerpc: BcHeader
          },
        },
        {
          path: '/activity',
          name: 'activity',
          components: {
            default: BcActivity,
            footerpc: BcFooter,
            headerpc: BcHeader
          },
        },
        {
          path: '/login',
          name: 'login',
          component: Login,
        },
        {
          path: '/signup',
          name: 'signup',
          component: Signup
        },
        {
          path: '/findpwd',
          name: 'findpwd',
          component: FindPwd
        },
        {
          path: '/home',
          name: 'home',
          components: {
            default: Home,
            footnavphone: FootnavPhone
          },
          meta: {
            requireAuth: true
          }
        },
        {
          path: '/order/confirmation/:id',
          name: 'confirmation',
          component: OrderConfirmation 
        },
        {
          path: '/order/success',
          name: 'success',
          component: OrderSuccess 
        },
        {
          path: '/lotterys',
          name: 'lotterys',
          components: {
            default: BuyLottery,
            headerpc: BcHeader,
            footnavphone: FootnavPhone,
            footerpc: BcFooter
          },
          meta: {
            requireAuth: true
          }
        },
        {
          path: '/select-number',
          components: {
            default: SelectNumber,
            footerpcsub: BcFooterSub
          },
          // component: SelectNumber,
          meta: {
            requireAuth: true
          },
          children: [
            {
              path: 'bjsc',
              name: 'bjracer',
              component: BjRacer,
              meta: {
                requireAuth: true
              }
            },
            {
              path: 'cqssc',
              name: 'shishicai',
              component: CqSsc,
              meta: {
                requireAuth: true
              }
            },
            {
              path: 'xglhc',
              name: 'liuhecai',
              component: XgLhc,
              meta: {
                requireAuth: true
              }
            },
            {
              path: 'xyks',
              name: 'kuaisan',
              component: XyKs,
              meta: {
                requireAuth: true
              }
            },
            {
              path: 'bj28',
              name: 'bj28',
              component: BjEb,
              meta: {
                requireAuth: true
              }
            },
            {
              path: '11xuan5',
              name: '11xuan5',
              component: JsXw,
              meta: {
                requireAuth: true
              }
            },
            {
              path: 'order-confirm',
              name: 'confirm',
              component: OrderConfirmation,
              meta: {
                requireAuth: true
              }
            }
          ]
        },
        {
          path: '/orders',
          name: 'orders',
          components: {
            default: OrderUnsettle,
            footnavphone: FootnavPhone,
            footerpcsub: BcFooterSub
          },
          meta: {
            requireAuth: true
          }
        },
        {
          path: '/orders/records/:id',
          name: 'orders/record',
          components: {
            default: OrderRecords,
            footerpcsub: BcFooterSub
          },
          // component: OrderRecords,
          meta: {
            requireAuth: true
          }
        },
        {
          path: '/me',
          name: '/me',
          components: {
            default: BcMe,
            footnavphone: FootnavPhone
          },
        },
        {
          path: '/my-account',
          name: 'myaccount',
          components: {
            default: MyAccount,
            footerpcsub: BcFooterSub
          },
          // component: MyAccount,
          children: [
            {
              path: 'wallet',
              name: 'wallet',
              component: MyWallet
            },
            {
              path: 'msg',
              name: 'msg',
              component: MyMsg
            },
            {
              path: 'setting',
              name: 'setting',
              component: MySettings
            }
          ],
          redirect: '/my-account/wallet'
        },
        {
          path: '/add-member',
          name: 'addmember',
          component: AddMembers
        },
        // {
        //   path: '/my-account',
        //   name: 'my-account',
        //   components: {
        //     default: MyAccount,
        //     footerpcsub: BcFooterSub
        //   },
        //   // component: MyAccount
        // },
        {
          path: '/me/report',
          name: 'me-report',
          // component: MyReport,
          components: {
            default: MyReport,
            footerpcsub: BcFooterSub
          }
        },
        {
          path: '/me/member-management',
          name: 'member-management',
          // component: MemberManagement,
          components: {
            default: MemberManagement,
            footerpcsub: BcFooterSub
          }
        },
        {
          path: '/me/recommend-link',
          name: 'recommend-link',
          component: RecommendLink
        },
        {
          path: '/me/recommend-link/detail/:id',
          name: 'link-detail',
          component: LinkDetail
        },
        {
          path: '/me/add-members',
          name: 'add-member',
          component: AddMembers
        },
        {
          path: '/me/recommend-link/add',
          name: 'recommend-link-add',
          component: AddLink
        },
        {
          path: '/account-update',
          name: 'account-update',
          components: {
            default: AccountUpdate,
            footnavphone: FootnavPhone,
            footerpcsub: BcFooterSub
          },
        },
        {
          path: '/account-update/me/detail/:id',
          name: 'account-update-detail',
          component: PersonalDetail
        },
        {
          path: '/account-update/member/detail/:id',
          name: 'account-update-member-detail',
          component: MemberDetail
        },
        {
          path: '/lottery/trends',
          name: 'lottery-trends',
          component: LotteryTrends
        }

    ]
})

router.beforeEach((to, from, next) => {
  //如果未匹配到路由
  if (to.matched.length == 0) { 
    //如果上级也未匹配到路由则跳转登录页面，如果上级能匹配到则转上级路由
    from.name ? next({ name:from.name }) : next('/')
  } else {
    //如果匹配到正确跳转
    next()
  }
});

export default router